package com.hxzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxzy.mapper.BookMapper;
import com.hxzy.mapper.BookTypeMapper;
import com.hxzy.pojo.Book;
import com.hxzy.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zl
 * @create 2020-10-28 9:55
 */
@Transactional
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private BookTypeMapper bookTypeMapper;
    @Override
    public List<Book> selectAll() {
        return bookMapper.selectAll();
    }

    @Override
    public int addBook(Book book) {
        return bookMapper.addBook(book);
    }

    @Override
    public int deleteBook(Integer id) {
        return bookMapper.deleteBook(id);
    }

    @Override
    public Book selectBookById(Integer id) {

        return bookMapper.selectBookById(id);
    }

    @Override
    public int updateBook(Book book) {
        return bookMapper.updateBook(book);
    }

    @Override
    public PageInfo<Book> getBookByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Book> books = bookMapper.selectAll();
        PageInfo<Book> pageInfo = new PageInfo<>(books);
        return pageInfo;
    }

    @Override
    public PageInfo<Book> getBooksByPrice(Integer pageNum, Integer pageSize, Double min, Double max) {
        PageHelper.startPage(pageNum,pageSize);
        List<Book> books = bookMapper.getBooksByPrice(min, max);
        PageInfo<Book> pageInfo = new PageInfo<>(books);
        return pageInfo;
    }
}
